package org.tabcap.gui.menu.edit;

import java.awt.event.ActionListener;

import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;

import org.tabcap.TCInstance;

import static java.awt.event.InputEvent.*;

public class TCEditMenu extends JMenu
{
	private static final long serialVersionUID = -5025706726629036744L;

	public TCEditMenu(TCInstance manager)
	{
		super("Edit");
		addOption("Undo", manager.undoAction(), 'Z', CTRL_DOWN_MASK);
		addOption("Redo", manager.redoAction(), 'Y', CTRL_DOWN_MASK);
		addSeparator();
		addOption("Cut", manager.cutAction(), 'X', CTRL_DOWN_MASK);
		addOption("Copy", manager.copyAction(), 'C', CTRL_DOWN_MASK);
		addOption("Paste", manager.pasteAction(), 'V', CTRL_DOWN_MASK);
	}
	
	public void addOption(String name, ActionListener listener)
	{
		JMenuItem option = new JMenuItem(name);
		if(listener != null)
			option.addActionListener(listener);
		add(option);
	}
	
	public void addOption(String name, ActionListener listener, Character keyChar, int modifiers)
	{
		JMenuItem option = new JMenuItem(name);
		option.setAccelerator(KeyStroke.getKeyStroke(keyChar, modifiers));
		if(listener != null)
			option.addActionListener(listener);
		add(option);
	}
}